'use strict';

const Controller = require('egg').Controller;

class CollectController extends Controller {
  async index() {
    const { ctx } = this;
    var {id} = ctx.query;
    console.log(id)
    var data = await ctx.service.top250.updateOne(id)
    console.log(data)
   /*  if(data.nModified){      //输出为1收藏成功
      ctx.body = {
          code:200,
          msg:"收藏成功"
      }
    }else{
        ctx.body = {
            code:400,
            msg:"warning 已经收藏成功,不用重复收藏"
        }
    } */
    ctx.redirect("/")
  }
  async cancel() {
    const { ctx } = this;
    var {id} = ctx.query;
    console.log(id)
    var data = await ctx.service.top250.updateTwo(id)
    console.log(data)
    if(data.nModified){
      ctx.body = {
          code:200,
          msg:"取消收藏"
      }
  }else{
      ctx.body = {
          code:400,
          msg:"warning 已经取消收藏,不用重复操作"
      }
  }
  ctx.redirect("/")
  }
}

module.exports = CollectController;
